package com.yang.controller.wx;




import com.yang.bean.MarketUser;

import com.yang.bean.common.BaseParam;
import com.yang.bean.common.BaseRespVo;
import com.yang.bean.common.CommonData;
import com.yang.bean.dhr.MarketCommentBo;
import com.yang.bean.dhr.MarketSubmitBo;
import com.yang.service.wx.WxOrderService;
import com.yang.utils.UserUtil;
import org.apache.shiro.web.session.mgt.DefaultWebSessionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author dinghongrui
 * @create 2022/09/09 17:18
 */
@RestController
@RequestMapping("wx/order")
public class WxOrderController {
    @Autowired
    WxOrderService wxOrderService;

    /**
     * @return com.yang.bean.common.BaseRespVo
     * @author dinghongrui
     * @description //TODO
     * @date 2022/9/9 22:17
     * @parma [marketCommentBo]
     **/

    @RequestMapping("comment")
    public BaseRespVo comment(@RequestBody MarketCommentBo marketCommentBo) {

        int code = wxOrderService.comment(marketCommentBo);
        if (code == 404) {
            return BaseRespVo.error("逾期不能评价");
        } else {
            return BaseRespVo.ok(null);
        }
    }


    @Autowired
    DefaultWebSessionManager defaultWebSessionManager;
    @RequestMapping("list")
    public BaseRespVo list(Integer showType, BaseParam baseParam, HttpServletRequest request) {
        MarketUser userMsg = UserUtil.getUserMsg(request, defaultWebSessionManager);
        Integer id = userMsg.getId();
        CommonData commonData = wxOrderService.queryAllList(showType, baseParam,id);
        return BaseRespVo.ok(commonData);
    }

    @RequestMapping("detail")
    public BaseRespVo getDetail(Integer orderId) {
        BaseRespVo baseRespVo = wxOrderService.queryDetails(orderId);
        return baseRespVo;
    }

    @RequestMapping("cancel")
    public BaseRespVo cancel(@RequestBody Map map) {
        wxOrderService.cancel(map);
        return BaseRespVo.ok();
    }

    @RequestMapping("refund")
    public BaseRespVo refund(@RequestBody Map map) {
        wxOrderService.refund(map);
        return BaseRespVo.ok();
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Map map) {
        wxOrderService.delete(map);
        return BaseRespVo.ok();
    }

    @RequestMapping("confirm")
    public BaseRespVo confirm(@RequestBody Map map) {
        wxOrderService.confirm(map);
        return BaseRespVo.ok();
    }

    @RequestMapping("goods")
    public BaseRespVo returnGoods(Integer orderId, Integer goodsId) {
        BaseRespVo baseRespVo = wxOrderService.returnGoodMsg(orderId,goodsId);
        return baseRespVo;
    }

    @RequestMapping("submit")
    public BaseRespVo submit(@RequestBody MarketSubmitBo marketSubmitBo) {
        BaseRespVo baseRespVo = wxOrderService.submit(marketSubmitBo);
        return baseRespVo;
    }

    @RequestMapping("prepay")
    public BaseRespVo prePay(@RequestBody Map map) {
        Integer orderId = (Integer) map.get("orderId");
        if (orderId == null || orderId == 0) {
            return BaseRespVo.error("参数不合法");
        }
        wxOrderService.prepay(orderId);
        return BaseRespVo.ok();
    }
}
